﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing;

namespace UniCT.LinkShareWpf.Interface
{
    [DataContract]
    public class NetResource : Resource
    {
          [DataMember]
          public Guid Id
        {
            get;
            set;
        }

          [DataMember]
          public Uri Sender
        {
            get;
            set;
        }

          [DataMember]
          public byte[] ImageBuffer
          {
              set;
              get;
          }

          public NetResource(Resource resource)
            : base(resource)
        {
            
            string IPserver = "87.12.210.38";// System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())[3].ToString();
            //foreach (System.Net.IPAddress IP in System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()))
            //    if (IP.ToString().Split('.')[0] == "151" || IP.ToString().Split('.')[0] == "172" || IP.ToString().Split('.')[0] == "79" || IP.ToString().Split('.')[0] == "87")
            //    {
            //        IPserver = IP.ToString();
            //        break;
            //    }
            Sender = new UriBuilder(Uri.UriSchemeHttp, IPserver, OperationContext.Current.Channel.LocalAddress.Uri.Port, "LinkShareWpf").Uri;



            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            string photolocation = "../../Covers/" + System.IO.Path.GetFileName(resource.CInfo.CoverName);
            bf.Serialize(ms, new Bitmap(@photolocation));
            ImageBuffer = ms.GetBuffer();


            //string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            //String photolocation = path + @"\..\..\Covers\" + value;
            //BitmapImage bitmap = new BitmapImage(new Uri(photolocation));
          }




    }
}
